package com.chenwei.lambda;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @BelongsProject: Spring-boot-3
 * @BelongsPackage: com.chenwei.lambda
 * @Author: Chen Wei
 * @CreateTime: 2024-01-07  00:38
 * @Description: TODO
 * @Version: 1.0
 */


interface MyInterface {
    int sum(int i, int j);
}

interface MyHaHa {
    void out();
}

interface MyHeHe {
    String out(String printStr);
}

class MyInterfaceImpl implements MyInterface {

    @Override
    public int sum(int i, int j) {
        return i + j;
    }
}

@SuppressWarnings("all")
public class Lambda {
    public static void main(String[] args) {
        var names = new ArrayList<String>();
        names.add("ahangsan");
        names.add("disi");
        names.add("cangwu");
        names.add("rhaoliu");

        //比较器
/*        Collections.sort(names, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                    return o2.compareTo(o1);
            }
        });*/
        //比较器简化写法 直接写函数式接口
//        Collections.sort(names,(o1,o2)-> o1.compareTo(o2));


        //直接告诉他该用String类的比较方法
        Collections.sort(names, String::compareTo);
        System.out.println(names);

        Thread thread = new Thread(() -> System.out.println("我启动了"));


        thread.start();


    }

    public static void main02(String[] args) {
        //1.自己创建
        MyInterface myInterface = new MyInterfaceImpl();
        System.out.println(myInterface.sum(1, 2));


        //2.创建匿名
        MyInterface myInterface1 = new MyInterface() {
            @Override
            public int sum(int i, int j) {
                return i + j;
            }
        };
        System.out.println(myInterface1.sum(1, 2));
        //3.lamda完整写法 参数列表+箭头+方法体
        MyInterface myInterface2 = (i, j) -> {
            return i + j;
        };
        System.out.println(myInterface2.sum(1, 2));


        MyHaHa myHaHa = () -> {
            System.out.println("haha");
        };
        myHaHa.out();

        MyHeHe myHeHe = y -> {
            return y;
        };
        System.out.println(myHeHe.out("hello world!!"));


        MyHeHe myHeHe1 = y -> y + "--------------";

        System.out.println(myHeHe1.out("hello world"));
        //完整写法如上
        //简短写法
        //1.参数类型可以不写，只写参数名，参数变量名随意定义,参数表可以只有一个()
        //参数只有一个。那么可以只写参数名，不用写()
        //2.


        //
    }
}
